package com.charlie.meetingmanagement.controller;


import com.charlie.meetingmanagement.pojo.po.PageBean;
import com.charlie.meetingmanagement.pojo.po.Rental;
import com.charlie.meetingmanagement.pojo.po.Result;
import com.charlie.meetingmanagement.pojo.vo.RuquestByTimeVo;
import com.charlie.meetingmanagement.requests.GetRentalInfo_request;
import com.charlie.meetingmanagement.service.RentalService;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

@Slf4j
@RestController
@CrossOrigin(origins = "*")
public class RentalController {

    @Resource
    private RentalService rentalService;

    //    条件分页获取rental数据
    @GetMapping("/rental/rentalInfoMore")
    public Result rentalInfoMore(@RequestParam(defaultValue = "1") Integer page,
                                 @RequestParam(defaultValue = "10") Integer pageSize,
                                 @RequestParam(required = false) Integer meetingroomId,
                                 @RequestParam(required = false) String meetingroomRentaldateTemp,
                                 @RequestParam(required = false) Integer meetingroomRentaltime,
                                 @RequestParam(required = false) Integer userId,
                                 @RequestParam(required = false) Integer approveId) {
        log.info("分页查询rental数据");
        LocalDate meetingroomRentaldate = null;
        if (meetingroomRentaldateTemp != null)
            meetingroomRentaldate = LocalDate.parse(meetingroomRentaldateTemp);
        PageBean pageBean = rentalService.page(page, pageSize, meetingroomId, meetingroomRentaldate, meetingroomRentaltime,
                userId, approveId);
        return Result.success(pageBean);
    }
//  前台根据日期获得 某个会议室的 各个时间的使用情况
    @PostMapping("/rental/getRentalInfo")
    public Result getRentalInfo(@RequestBody GetRentalInfo_request request){
        System.out.println(request);
        LocalDate rentaldate = request.getRentaldate();
        Integer meetingroomId = request.getMeetingroomId();

        RuquestByTimeVo ruquestByTimeVo= rentalService.getRentalInfo(rentaldate,meetingroomId);
        System.out.println(ruquestByTimeVo);
        return Result.success(ruquestByTimeVo);
    }
    @PostMapping("/rental/insertRental")
    public Result insertRental(@RequestBody Rental rental) {
        log.info("insertRental");
        return rentalService.insertRental(rental);
    }

//    撤销已经同意的会议申请，即删除其在rental的记录，并将记录返回到request中
    @PostMapping("/rental/regretRental")
    public Result regretRental(@RequestBody Rental rental) {
        log.info("regretRental");
        return rentalService.regretRental(rental);
    }

//    删除已同意的会议申请
    @PostMapping("/rental/deleteRental")
    public Result deleteRental(@RequestBody Rental rental) {
        log.info("deleteRental");
        return rentalService.deleteRental(rental);
    }
}
